package cn.ccit.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

import cn.ccit.base.BaseConstants;

public class ConstantsUtil {
	
	
	
	
	/**
	 * 将枚举星期转换中文
	 * 
	 * @param w
	 *            传入一个星期枚举值
	 * @return s 返回枚举周几的中文映射
	 */
	public static String weekChangeToChinese(BaseConstants.WeekMapping w) {
		String s = "星期日";
		switch (w) {
		case MON:
			s = "星期一";
			break;
		case TUE:
			s = "星期二";
			break;
		case WED:
			s = "星期三";
			break;
		case THU:
			s = "星期四";
			break;
		case FRI:
			s = "星期五";
			break;
		case SAT:
			s = "星期六";
			break;
		default:
		}
		return s;
	}

	/**
	 * 菜品类型
	 * @param d
	 * @return
	 */
	public static String dishTypeToChinese(BaseConstants.DishType d) {
		String s = BaseConstants.HOTDISH;
		switch (d) {
		case Soup:
			s = BaseConstants.SOUP;
			break;
		case StapleFood:
			s = BaseConstants.STAPLEFOOD;
		default:
			break;
		}
		return s;
	}
	/**
	 * 菜品状态
	 * @param d
	 * @return
	 */
	public static String dishStateToChinese(BaseConstants.DishState d) {
		String s = BaseConstants.NOSERVEDISH;
		switch (d) {
		case AlreadyServeDish:
			s = BaseConstants.ALREADYSERVEDISH;
			break;
		case RetreatFood:
			s = BaseConstants.RETREATFOOD;
		default:
			break;
		}
		return s;
	}
	/**
	 * 支付方式
	 * @param p
	 * @return
	 */
	public static String payWayChangeToChinese(BaseConstants.PayWay p) {
		String s = BaseConstants.AlIPAY;
		switch (p) {
		case WEIXING:
			s = BaseConstants.WEIXING;
			break;
		case CASH:
			s = BaseConstants.CASH;
			break;
		default:
			break;
		}
		return s;
	}
	/**
	 * 支付状态
	 * @param p
	 * @return
	 */
	public static String payStateToChinese(BaseConstants.PayState p) {
		String s = BaseConstants.NOPAY;
		switch (p) {
		case ALREADYPAY:
			s = BaseConstants.ALREADYPAY;
			break;
		default:
			break;
		}
		return s;
	}
	/**
	 * 餐桌状态
	 * @param t
	 * @return
	 */
	public static String tableStateToChinese(BaseConstants.TableState t) {
		String s = BaseConstants.CLOSETABLE;
		switch (t) {
		case OpenTable:
			s = BaseConstants.OPENTABLE;
			break;
		default:
			break;
		}
		return s;
	}
	
	public static int getIntegerFromStringNum(String id){
        String reg = "^\\+?[1-9][0-9]*$";
        if(Pattern.compile(reg).matcher(id).find()){
        	return Integer.valueOf(id);
        }
        return -1;
    }
	
	/**
	 * 
	 * 方法功能说明：获取订单序列号   时间+餐桌id+门店id
	 * 创建：2016年11月14日 by Administrator   
	 * 修改：日期 by 修改者  
	 * 修改内容：  
	 * @参数： @param tableId
	 * @参数： @param tid
	 * @参数： @return      
	 * @return long     
	 * @throws
	 */
	public static long getSerialsNumber(int tableId,int tid) {
		SimpleDateFormat sFormat =new SimpleDateFormat("yyMMddHHmmss");
		Long serialsNumber=Long.valueOf(sFormat.format(new Date()))*1000+tableId*1000+tid;

		return serialsNumber;
	}
	
	public static Map<String, String> getNowTimeMap() {
		SimpleDateFormat sFormat =new SimpleDateFormat("yyyy-MM-dd-hh-mm");
		String time=sFormat.format(new Date());
		String temp[]=time.split("-");
		Map<String, String> timeMap=new HashMap<String, String>();
		timeMap.put(BaseConstants.YEAR, temp[0]);
		timeMap.put(BaseConstants.MONTH, temp[0]+"-"+temp[1]);
		timeMap.put(BaseConstants.DATE, temp[0]+"-"+temp[1]+"-"+temp[2]);
		timeMap.put(BaseConstants.CRTEAT_TIME,time);
		return  timeMap;
	}
}
